var chatTable;
function getchecliveList() {
	if (typeof chatTable !== 'undefined') {
		chatTable.fnPageChange('first');
		return;
	}
	var i = 1;
	chatTable = $("#chatList")
			.DataTable(
					{
						"sAjaxSource" : _path + "/checkLive/queryByPage",
						"fnServerParams" : function(aoData) {
							aoData.push(
									{"name" : "liveId","value" : $("#liveId").val()},
									{"name" : "sendStatus","value" : $("#sendStatus").val()},
									{"name" : "userNickName","value" : $("#userNickName").val()},
									{ "name": "fromDate", "value": $("#fromDate").val() },
						            { "name": "toDate", "value": $("#toDate").val() }
							);
						},
						"sServerMethod" : "POST",
						"sAjaxDataProp" : "dataList",
						"fnCreatedRow" : function() {
							i++;
						},
						"fnPreDrawCallback" : function() {
							i = 1;
						},
						"aoColumns" : [
								{
									"sTitle" : "序号",
									"sWidth" : "2%",
									"mData" : function() {
										return i;
									}
								},
								/*{
									"sTitle" : "直播ID",
									"mData" : "liveId",
									"sWidth" : "2%"
								},
								{
									"sTitle" : "直播名称",
									"mData" : "live.name",
									"sWidth" : "6%"
								}
								,*/
								{
									"sTitle" : "用户昵称",
									"mData" : "userNickName",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "当前状态",
									"mData" : "sendStatus",
									"sWidth" : "2%",
									"mRender" : function(data) {
										var chatType = '';
										switch (data) {
										case '0':
											chatType = '已申请';
											break;
										case '1':
											chatType = '通过';
											break;
										case '2':
											chatType = '驳回';
											break;
										}
										return chatType;
									}
								},
								{
									"sTitle" : "申请时间",
									"mData" : "createTime",
									"sWidth" : "10%"
								}
								,
								{
									"sTitle" : "昵称",
									"mData" : "userNickName",
									"sWidth" : "10%"
								}
								,
								{
									"sTitle" : "申请人",
									"mData" : "name",
									"sWidth" : "10%"
								}
								,
								{
									"sTitle" : "申请人电话",
									"mData" : "phone",
									"sWidth" : "10%"
								}
								,
								{
									"sTitle" : "操作",
									"sWidth" : "10%",
									"mData" : function(data) {
									
													 var status = '<a href="javascript:inquiryok('
															+ data.id
															+ ',1);" class="btn default btn-xs purple"><i class="icon-ok" title="通过">通过</i></a>';
													  status += '&nbsp;<a href="javascript:inquiryok('
															+ data.id
															+ ',2);"  class="btn default btn-xs red"><i class="fa icon-off" title="驳回">驳回</i></a>';
								                  /*  status += '&nbsp;<a href="javascript:inquiry('
														+ data.id
														+ ');"  class="btn default btn-xs red"><i class="fa fa-trash-o" title="删除">删除</i></a>';*/
										return status;
									}
								}  
								]
					});
}


//获取所有直播的信息
function queryAllLive(lid){
	 $.ajax({										
		    url: _path + "/chat/queryAllLive?lid="+lid,
		    type: "POST",
		    dataType: "json",
		    async: false,
		    success: function(jsonMap) {
		    	var list = jsonMap.dataList;
		        if(list.length>0){
		        	for(var i=0;i<list.length;i++){
						var live = list[i];
						var op ="";
						  if ( lid == live.id) {
							  op = "<option value="+live.id+" selected>"+live.name+"</option>";
						  }else{
							  op = "<option value="+live.id+" >"+live.name+"</option>";
						  }
						$("#liveId").append(op);
		        	}
		        }
		    }
		});
}


function inquiry(id) {

	layer.confirm('您确定要删除吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		layer.closeAll('dialog');
		$.ajax({
			url : _path + "/checkLive/del/" + id,
			type : "get",
			dataType : "json",
			async : false,
			error : function(request) {
				alert("连接错误！");
			},
			success : function(data) {
				  if(data.msg=='成功'){
					  layer.close
					  App.bubble(200, "删除成功");
					  getchecliveList();
				  }else{
					  App.bubble(200, "删除异常");
				  }
			}
		});
	}, function() {

	});
}
function inquiryok(id,tyoe) {

		$.ajax({
			url : _path + "/checkLive/updacklc?types="+tyoe+"&id=" + id,
			type : "get",
			dataType : "json",
			async : false,
			error : function(request) {
				alert("连接错误！");
			},
			success : function(data) {
				  if(data.msg=='成功'){
					  layer.close
					  App.bubble(200, "成功");
					  getchecliveList();
				  }else{
					  App.bubble(200, "异常");
				  }
			}
		});
 
}
